package com.will.willaicodemother.core.saver;

import cn.hutool.core.util.StrUtil;
import com.will.willaicodemother.ai.enums.CodeGenTypeEnum;
import com.will.willaicodemother.ai.model.HtmlCodeResult;
import com.will.willaicodemother.exception.BusinessException;
import com.will.willaicodemother.exception.ErrorCode;

/**
 * @author will
 * @since 2025/8/8 17:20
 */
public class HtmlCodeFileSaverTemplate extends CodeFileSaverTemplate<HtmlCodeResult>{


    @Override
    public CodeGenTypeEnum getCodeGenType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void saveFiles(String uniqueDirPath, HtmlCodeResult result) {
        writeToFile(uniqueDirPath, "index.html", result.getHtmlCode());
    }

    @Override
    protected void validateInput(HtmlCodeResult result) {
        super.validateInput(result);
        if (StrUtil.isBlank(result.getHtmlCode())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "HTML代码不能为空");
        }
    }
}
